﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using DBUtility;
using IDAL;
using Model;

namespace DAL
{
    public class ProductType_Airtightness : BaseRepository<ProductType_AirtightnessInfo>, IProductType_Airtightness
    {
        #region 静态变量部分
        private const string PARM_ID = "@ID";
        private const string PARM_PRODUCTTYPE_ID = "@ProductTypeID";
        private const string PARM_PRODUCTTYPE_CHANNELNO = "@ChannelNo";
        private const string PARM_PRODUCTTYPE_SPECVALUE = "@SpecValue";
        private const string PARM_PRODUCTTYPE_INFLATEDURATION = "@InflateDuration";
        private const string PARM_PRODUCTTYPE_BALANCEDURATION1 = "@BalanceDuration1";
        private const string PARM_PRODUCTTYPE_BALANCEDURATION2 = "@BalanceDuration2";
        private const string PARM_PRODUCTTYPE_MEASUREDURATION = "@MeasureDuration";
        private const string PARM_PRODUCTTYPE_LEAKSPEC = "@LeakSpec";
        private const string PARM_PRODUCTTYPE_MINUSLEAKSPEC = "@MinusLeakSpec";
        private const string PARM_PRODUCTTYPE_PRODUCTCUBAGE = "@ProductCubage";
        #endregion

        #region 数据检索部分
        public IList<ProductType_AirtightnessInfo> LoadEntities()
        {
            return ExcuteSqlToGetEntities("ProductType_Airtightness_select");
        }

        public IList<ProductType_AirtightnessInfo> ProductType_Airtightness_GetbyPID(string productTypeID)
        {
            SqlParameter parm = new SqlParameter(PARM_PRODUCTTYPE_ID, SqlDbType.NVarChar, 50);
            parm.Value = productTypeID;
            return ExcuteSqlToGetEntities("ProductType_Airtightness_selectbyPID", parm);
        }

        /// <summary>
        /// Get an individual category based on a provided id
        /// </summary>
        /// <param name="categoryId">Category id</param>
        /// <returns>Details about the Category</returns>
        public ProductType_AirtightnessInfo LoadEntity<T1>(T1 id)
        {
            SqlParameter parm = GetParameter();
            //Bind the parameter
            parm.Value = id;
            return ExcuteSqlToGetEntity("ProductType_Airtightness_selectbyID", parm);
        }

        public ProductType_AirtightnessInfo ProductType_Airtightness_GetbyPIDCHNO(string productTypeID,int channelNO)
        {
            SqlParameter[] parm = GetPPIDCHNOParameters();
            //Bind the parameter
            parm[0].Value = productTypeID;
            parm[1].Value = channelNO;
            return ExcuteSqlToGetEntity("ProductType_Airtightness_selectbyPIDCHNO", parm);
        }
        #endregion

        #region 重写基类部分
        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override ProductType_AirtightnessInfo GetEntityRecord(SqlDataReader rdr)
        {
            ProductType_AirtightnessInfo pro = new ProductType_AirtightnessInfo(rdr.GetInt32(0), rdr.GetValue(1).ToString(), rdr.GetInt32(2), rdr.GetInt32(3)
                , rdr.GetInt32(4), rdr.GetInt32(5), rdr.GetInt32(6), rdr.GetInt32(7), rdr.GetInt32(8), rdr.GetInt32(9), rdr.GetInt32(10));
            return pro;
        }

        public override ProductType_AirtightnessInfo GetEntityRecord()
        {
            ProductType_AirtightnessInfo pro = new ProductType_AirtightnessInfo();
            return pro;
        }

        public override string GetInsertsp()
        {
            return "ProductType_Airtightness_Insert";
        }

        public override string GetUpdatesp()
        {
            return "ProductType_Airtightness_Update";
        }

        public override string GetDeletesp()
        {
            return "ProductType_Airtightness_Delete";
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_ID, SqlDbType.Int, 4);
            return Parm;
        }

        public SqlParameter[] GetPPIDCHNOParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_PRODUCTTYPE_ID, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_PRODUCTTYPE_CHANNELNO, SqlDbType.Int, 4)
                };
            return parms;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_ID, SqlDbType.Int, 4),
					new SqlParameter(PARM_PRODUCTTYPE_ID, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_PRODUCTTYPE_CHANNELNO, SqlDbType.Int, 4),
					new SqlParameter(PARM_PRODUCTTYPE_SPECVALUE, SqlDbType.Int, 4),
					new SqlParameter(PARM_PRODUCTTYPE_INFLATEDURATION, SqlDbType.Int, 4),
					new SqlParameter(PARM_PRODUCTTYPE_BALANCEDURATION1, SqlDbType.Int, 4),
					new SqlParameter(PARM_PRODUCTTYPE_BALANCEDURATION2, SqlDbType.Int, 4),
					new SqlParameter(PARM_PRODUCTTYPE_MEASUREDURATION, SqlDbType.Int, 4),
					new SqlParameter(PARM_PRODUCTTYPE_LEAKSPEC, SqlDbType.Int, 4),
					new SqlParameter(PARM_PRODUCTTYPE_MINUSLEAKSPEC, SqlDbType.Int, 4),
					new SqlParameter(PARM_PRODUCTTYPE_PRODUCTCUBAGE, SqlDbType.Int, 4),
                };
            return parms;
        }
        
        public override void SetParameters(ProductType_AirtightnessInfo productType, params SqlParameter[] Parms)
        {
            Parms[0].Value = productType.ID;
            Parms[1].Value = productType.ProductTypeID;
            Parms[2].Value = productType.ChannelNo;
            Parms[3].Value = productType.SpecValue;
            Parms[4].Value = productType.InflateDuration;
            Parms[5].Value = productType.BalanceDuration1;
            Parms[6].Value = productType.BalanceDuration2;
            Parms[7].Value = productType.MeasureDuration;
            Parms[8].Value = productType.LeakSpec;
            Parms[9].Value = productType.MinusLeakSpec;
            Parms[10].Value = productType.ProductCubage;
        }
        #endregion
    }
}
